package com.wxs.common.utils;

import java.io.Serializable;

public class R<T> implements Serializable {
	private static final int OK = 0;
	private static final int FAIL = 1;
	// private static final int UNAUTHORIZED = 2;
	private static final long serialVersionUID = -6373402751616512206L;

	private T data; // 服务端数据
	private int status = OK; // 状态码
	private String msg = ""; // 描述信息

	public static R<?> isOk() {
		return new R<>();
	}

	public static R<?> isFail() {
		return new R<>().status(FAIL);
	}

	public static R<?> isFail(Throwable e) {
		return isFail().msg(e);
	}

	public R<T> msg(Throwable e) {
		this.setMsg(e.toString());
		return this;
	}

	public R<T> data(T data) {
		this.setData(data);
		return this;
	}

	public R<T> status(int status) {
		this.setStatus(status);
		return this;
	}

	// Constructors
	public R() {
	}

	public T getData() {
		return data;
	}

	public void setData(T data) {
		this.data = data;
	}

	public int getStatus() {
		return status;
	}

	public void setStatus(int status) {
		this.status = status;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}
}
